#
#  Fastfile
#
#  For more information about the Fastfile, see:
#  You can find the documentation at https://docs.fastlane.tools
#
#  For a list of all available actions, check out
#  https://docs.fastlane.tools/actions
#

opt_out_usage

default_platform(:ios)
platform :ios do
  before_all do
    # This is required to setup the temporary keychain
    setup_circle_ci
  end
  desc "Builds using the dev environment"
  lane :dev do
    sync_code_signing(type: "appstore", readonly: true)
    build_app(
      clean: true,
      export_method: "app-store",
      include_bitcode: true,
      include_symbols: true,
      scheme: "Blockchain (Dev)",
      workspace: "Blockchain.xcworkspace"
    )
    if is_ci?
      # Send Slack notification to #ios-ci channel
      # slack(message: "App successfully build!")
    end
  end
  desc "Deploys staging environment build to TestFlight"
  lane :staging do
    build_app(
      clean: true,
      include_bitcode: true,
      include_symbols: true,
      scheme: "Blockchain (Staging)",
      workspace: "Blockchain.xcworkspace"
    )
    # upload_to_testflight
  end
  desc "Runs all unit tests"
  lane :execute_tests do
    scan(
      workspace: "Blockchain.xcworkspace",
      scheme: "Blockchain (Staging)",
      devices: ["iPhone X"],
      clean: true
    )
  end
  desc "Builds using the production environment"
  lane :code_signing do
    # Global parameters are loaded from the Matchfile
    match(type: "appstore", readonly: true)
    match(type: "adhoc", force_for_new_devices: true)
  end
  desc "Upload to TestFlight"
  lane :upload do
    match(type: "appstore", readonly: true)
    upload_to_testflight(
      ipa: "output/Blockchain.ipa",
      skip_submission: true,
      skip_waiting_for_build_processing: true
    )
  end
  desc "Download dSYM file from iTunes and uploads it to Crashlytics"
  lane :upload_dsyms do
    upload_symbols_to_crashlytics(
      dsym_path: "./output/Blockchain.app.dSYM.zip",
      gsp_path: "./Blockchain/Firebase/Prod/GoogleService-Info.plist"
    )
  end
end
